package com.hejun.student.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.*;

import com.baomidou.mybatisplus.extension.plugins.pagination.*;
import com.baomidou.mybatisplus.extension.service.impl.*;
import com.hejun.student.entity.Student;
import com.hejun.student.mapper.StudentMapper;
import com.hejun.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.*;


@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Autowired
    StudentMapper studentMapper;

    @Override
    public Page<Student> getPage(String studentName, Integer pageNum) {
        Page page = new Page(pageNum, 3);
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.hasText(studentName)) {
            queryWrapper.like(Student::getStudentname, studentName);
        }

        queryWrapper.orderByDesc(Student::getId);

        this.page(page, queryWrapper);

        return page;
    }
}
